extern crate rustc_serialize;

// 引入rustc_serialize模块
use rustc_serialize::json;

#[derive(RustcDecodable, RustcEncodable)]
pub struct TestStruct {
    data_int: u8,
    data_str: String,
    data_vector: Vec<u8>,
}

#[test]
fn json_test() {
    let object = TestStruct {
        data_int: 1,
        data_str: "homura".to_string(),
        data_vector: vec![2, 3, 4, 5],
    };

    // Serialize using `json::encode`
    let encoded = json::encode(&object).unwrap();
    println!("{}", encoded);

    // Deserialize using `json::decode`
    let decoded: TestStruct = json::decode(&encoded).unwrap();
    println!("data_int={}", decoded.data_int);
}

